﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Reflection;
using Metaspec;

// Dependent projects example.

namespace DependentProjectsExample
{
	class Program
	{
		static void Main(string[] args)
		{
			//creating project1
			ICsProject project1 = ICsProjectFactory.create(project_namespace.pn_project_namespace);
			project1.setBuildEntityModel(true);

			{
				//adding assemblies
				string assembly_path = Assembly.GetAssembly(typeof(object)).Location;
				byte[] assembly_buffer = File.ReadAllBytes(assembly_path);
				IExternalAssemblyModule module = IExternalAssemblyModuleFactory.create(assembly_buffer, assembly_path);
				project1.addExternalAssemblyModules(new IExternalAssemblyModule[] { module }, false, null);

				//adding C# file
				string directory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"..\..");
				string path = Path.Combine(directory, "Project1.cs");
				char[] buffer = File.ReadAllText(path).ToCharArray();
				ICsFile file = ICsFileFactory.create(buffer, path);
				project1.addFiles(file);
			}

			//creating project2
			ICsProject project2 = ICsProjectFactory.create(project_namespace.pn_project_namespace);
			project2.setBuildEntityModel(true);

			{
				//adding assemblies
				string assembly_path = Assembly.GetAssembly(typeof(object)).Location;
				byte[] assembly_buffer = File.ReadAllBytes(assembly_path);
				IExternalAssemblyModule module = IExternalAssemblyModuleFactory.create(assembly_buffer, assembly_path);
				project2.addExternalAssemblyModules(new IExternalAssemblyModule[] { module }, false, null);

				//adding C# file
				string directory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"..\..");
				string path = Path.Combine(directory, "Project2.cs");
				char[] buffer = File.ReadAllText(path).ToCharArray();
				ICsFile file = ICsFileFactory.create(buffer, path);
				project2.addFiles(file);

				//adding reference to project1
				project2.addProjectReferences(new ProjectReference(project1));
			}

			//creating solution
			ISolution solution = ISolutionFactory.create();
			solution.addProjects(project1);
			solution.addProjects(project2);

			//parsing
			solution.parse();
		}
	}
}
